const fs = require("fs");

function getBlocks(template, blocksSetting) {
    const blockContent = JSON.parse(fs.readFileSync(`./src/theme/${template}/lib/config/block.json`, "utf-8"));
    const blocks_setting = blockContent.list.map((blocks) => {
        blocks.sections = blocks.sections.map((block) => {
            if (blocksSetting[block]) {
                return {
                    name: blocksSetting[block].name,
                    type: "block",
                    icon: blocksSetting[block].icon,
                    routes: blocksSetting[block].routes || [],
                    id: block
                };
            }
            return {
                type: "block",
                id: block
            };
        });
        return blocks;
    });

    return { blockContent,blocks_setting };
}

module.exports = { getBlocks };
